package com.demo.pattern.single;

// 懒汉式，线程安全,同步方法
public class DemoTest5 {
    public static void main(String[] args) {
        System.out.println(Single3.getInstance() == Single3.getInstance());
    }
}

class Single5 {
    // 私有构造方法，外部不能new
    private Single5() {
    }

    public static Single5 instance;

    public static synchronized Single5 getInstance() {
        if (instance == null) {
            synchronized (Single5.class) {
                instance = new Single5();
            }
        }
        return instance;
    }
}